﻿using Spring.Context;
using Spring.Context.Support;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;

namespace LY.Manage.SpringNet
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            IApplicationContext ctx = ContextRegistry.GetContext(); 
            //MovieLister lister = (MovieLister)ctx.GetObject("MyMovieLister");
            IUserInfoService userInfoService = (IUserInfoService)ctx.GetObject("UserInfoService");
            MessageBox.Show(userInfoService.ShowMsg());

        }



        public string  GetMidStr(string str,string startStr,string endStr)
        {
            //<p ttm:role="caption" xml:id="subtitle1" end="00:00:04:00" begin="00:00:00:20"> [Music] </p>
            int iBeginIndex = 0;
            iBeginIndex = str.IndexOf(startStr);
            if (iBeginIndex==-1)
            {
                return "";
            }
            int iEndIndex = -1;
            iEndIndex = str.IndexOf(endStr);
            if (iEndIndex==-1)
            {
                return "";
            }
            string result = str.Substring(iBeginIndex+startStr.Length, iEndIndex - iBeginIndex-startStr.Length);
            return result;

        }
        private void button2_Click(object sender, EventArgs e)
        {

            try
            {
                String str = File.ReadAllText("video_cc.xml");
                str = str.Substring(str.IndexOf("<div region=\"subtitleArea\">"));


                string[] arr = Regex.Split(str, "<p ttm:role=\"caption\"", RegexOptions.IgnoreCase);
                System.Collections.ArrayList al = new System.Collections.ArrayList();


                //<p ttm:role="caption" xml:id="subtitle1" end="00:00:04:00" begin="00:00:00:20"> [Music] </p>
                for (int i = 1; i < arr.Length; i++)
                {

                    string xuhao = "";
                    string begin = "";
                    string end = "";
                    string zimu = "";

                    //解析数字
                    xuhao = GetMidStr(arr[i], "subtitle", "\" end");

                    //解析开始时间
                    begin = GetMidStr(arr[i], "begin=\"", "\">");


                    //解析结束时间
                    end = GetMidStr(arr[i], "end=\"", "\" begin");

                    //解析字幕
                    zimu = GetMidStr(arr[i], ">", "</p>");

                    al.Add(xuhao);
                    al.Add(begin + "-->" + end);
                    al.Add(zimu);



                }
                string[] arrRes = new string[al.Count];
                for (int i = 0; i < al.Count; i++)
                {
                    arrRes[i] = al[i].ToString();
                }

                File.WriteAllLines("asdf.test", arrRes);


              





            }
            catch
            {

            }
        }
    }
}
